home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / STUFFKB.V01 < prev    next >
Text File  |  1990-01-12  |  7KB  |  144 lines

  1. cseg    segment    
  2.     assume cs:cseg,ds:cseg
  3.     org 100h
  4. go:    JMP   START
  5.  
  6.          DB    0Dh,0Ah,'STUFFKB v 1.01 A Utility to Stuff the Keyboard with the Parameter String.',0Dh,0Ah
  7.          DB    'Written by Ed Derzawiec',0Dh,0Ah
  8.          DB    '6 Sweet Fern Rd, Cape Elizabeth, ME  04107',0Dh,0Ah
  9.          DB    'Declared Public Domain, 1989'
  10.          DB    1Ah           ;Clean up a listing of this .COM file
  11.  
  12.  
  13. ParamLen EQU   080h           ;PSP offset To Length Of Parameter String
  14. Params   EQU   081h           ;PSP offset to Parameters
  15.  
  16. A_BS     EQU   008h           ;ASCII Code for BackSpace
  17. A_ESC    EQU   01Bh           ;Escape
  18. A_CR     EQU   00Dh           ;Carrage Return
  19. A_BELL   EQU   007h           ;Bell
  20.  
  21.                              ;The Following are the control Words
  22.                              ;delimited by "~" characters on the command
  23.                              ;line to be translated into ASCII Code.
  24.                              ;This Table Format is "Word",-1,Code,...,0
  25.                              ;  "Word" is the Defined Control Word to Translate
  26.                              ;  -1 Delimits the Control Word
  27.                              ;  Code is the Assigned ASCII Code
  28.                              ;  And a Null Identifies the End of the Table
  29. Controls:DB    "CR",-1,A_CR,"BS",-1,A_BS,"ESC",-1,A_ESC,0
  30. ControlLen DW  ?             ;The Length of the above string
  31.  
  32. Start:   mov   al,2
  33.      CMP   al, byte ptr [ParamLen]
  34.          JL    Exit          ;Exit if No Parameters Passed
  35.          CALL  GetControlLength
  36.          CALL  StuffKBRD
  37. Exit:    SUB   AH,AH
  38.          INT   21h           ;Exit Program
  39.  
  40. GetControlLength         Proc NEAR
  41.                  ;This Procedure Assigns the Length of the
  42.                              ;Control Character String Defined above.
  43.          MOV   DI,OFFSET(Controls)
  44.          MOV   AX,0
  45.          MOV   CX,-1
  46.          REPNE SCASB       ;Find the End of the Control String
  47.          NEG   CX
  48.          DEC   CX
  49.          DEC   CX            ;Normalize CX to the Length of the Control String
  50.          MOV   ControlLen,CX ;and store the value
  51.          RET
  52. GetControlLength         ENDP
  53.  
  54. StuffKBRD         Proc NEAR
  55. ;              This routine will stuff the KeyBoard Buffer with the Parameter passed
  56. ;              It won't work for extended characters (NON ASCII)
  57. Head     EQU   01Ah
  58. Tail     EQU   01Ch
  59. Kbuffer  EQU   01Eh
  60.  
  61.      PUSH  ES
  62.          MOV   AX,040h     ;BIOS Keyboard Buffer resides in Page 40
  63.      MOV   ES,AX
  64.          MOV   SI,Params+1   ;Move Past FileName Delimiter (Space)
  65.          MOV   DI,KBuffer
  66.          MOV   word ptr ES:[Head],Kbuffer ;Initialize Keyboard Buffer Pointers
  67.          MOV   word ptr ES:[Tail],Kbuffer
  68.          MOV   AH,0          ;Null Out Scan Code (Not Normally Important)
  69. Stuff1:  LODSb               ;Get ASCII into AL
  70.          CMP   AL,A_CR       ;End Stuff on Carrage Return in Parameter String
  71.          JE    Stuff9        ;Exit on end of string
  72.          CMP   AL,"~"        ;Control Character Delimiter
  73.          JNE   Stuff2
  74.          CALL  ControlDecode
  75. Stuff2:  STOSw               ;Put into Keyboard Buffer (SCAN Code = 0)
  76.          CMP   DI,Kbuffer+30 ;Stuff a Max of 15 Characters
  77.          JB    Stuff1  
  78. Stuff9:  MOV   ES:[Tail],DI  ;Identify the end of the Keyboard Buffer
  79.          POP   ES
  80.          RET
  81. StuffKBRD         ENDP
  82.  
  83. ControlDecode         Proc  NEAR          ;Compares the Delimited Control Command at [SI]
  84.                              ;With the Control String ([DI]) to find match
  85.                              ;and return ASCII equivalent in AL (incrementing SI)
  86.          PUSH  ES            ;Save The KeyBoard Data Segment
  87.          PUSH  DI            ;And Current Pointer
  88.          PUSH  DS
  89.          POP   ES            ;Move DS to ES
  90.          CALL  UPPER         ;Convert Control Word in Params to UPPER CASE
  91.          MOV   DI,OFFSET(Controls)
  92.          MOV   CX,ControlLen ;Compare to End of Control String
  93. Cntl1:   PUSH  SI            ;Store in case you need to loop by a mismatch
  94.          PUSH  DI            ;  "
  95.          PUSH  CX            ;  "
  96.          CMPSb               ;Does The First Character Match
  97.          JNE   Cntl2         ;No, Try Next Word in Control List
  98.          REPE  CMPSb               ;Increment SI,DI until a Mismatch is found
  99.          CMP   byte ptr [DI-1],-1    ;Did the Match end in a proper control delimiter?
  100.          JE    Cntl5         ;Possibly, Yes
  101. Cntl2:   POP   CX            ;No.. Restore to value at start of Word Match
  102.          POP   DI            ;  "
  103.          POP   SI            ;  "
  104.          MOV   AL,-1
  105.          REPNE SCASb         ;Go to Next Control Word in Control Word List
  106.          INC   DI            ;Skip ASCII Code of previous character
  107.          DEC   CX            ;  "
  108.          CMP   CX,0          ;Has the end of the Control List been reached?
  109.          JNE   Cntl1         ;No.. Look for another initial Match
  110.                              ;Yes.. Push a Bell Character for this Control
  111.          PUSH  SI
  112.          POP   DI            ;Move SI to DI
  113.          MOV   AL,"~"
  114.          MOV   CX,80         ;Allow for a Maximum 80 Character Parameter
  115.          REPNE SCASb         ;Go to Next Control Word in the Parameter String
  116.          PUSH  DI
  117.          POP   SI            ;Move DI to SI
  118.          MOV   AL,A_Bell     ;Stuff a beep on No Match Found...
  119.          JMP   Cntl9         ;Exit Subroutine
  120. Cntl5:   CMP   byte ptr [SI-1],"~"   ;Did the Match end in a proper control Delimiter?
  121.          JNE   Cntl2         ;No...
  122.          POP   CX            ;Yes... Discard Variables On Successful Match
  123.          POP   DX            ;  "
  124.          POP   CX            ;  "
  125.          MOV   AL,byte ptr [DI]      ;Load the Control Characters ASCII Code in AL
  126. Cntl9:   POP   DI            ;Restore the pointer to the Keyboard Buffer
  127.          POP   ES            ;And Segment
  128.          RET
  129. ControlDecode      ENDP
  130.  
  131. Upper   PROC  NEAR          ;Converts Control Word at SI to Upper Case
  132.      PUSH  SI            ;Store the Pointer to the Start of the Word
  133. Upper1:  CMP   byte ptr [SI],"~"     ;Done?
  134.          JE    Upper9
  135.          LODSb               ;Get the Character in the control string
  136.          AND   AL,11011111B ;Convert to upper CASE
  137.          MOV   byte ptr [SI-1],AL    ;Store Converted Character
  138.          JMP   Upper1
  139. Upper9:  POP   SI            ;Restore Pointer
  140.          RET
  141. Upper    ENDP
  142. cseg    ends
  143.     end    go
  144.